import { pages, LoadFrom } from '@/api/feedback/feedback'

const state = {
  controllerName: 'feedback',
  dataList: {
    listLoading: false,
    list: [],
    // getShipAddressList: [],
    searchForm: {
      Contents: '',
      pageSize: 10,
      pageIndex: 1,
      dataCount: 0,
      pageCount: 0
    }
  },
  form: {
    formState: false,
    model: {}
  }
}
const mutations = {
  pageSizeChange(state, par) {
    state.dataList.searchForm.pageSize = par
    this.dispatch(`feedback/${state.controllerName}/findList`)
  },
  currentPageChange(state, par) {
    state.dataList.searchForm.pageIndex = par
    this.dispatch(`feedback/${state.controllerName}/findList`)
  }
}

const actions = {
  loadNewForm(context) {
    var _state = context.state
    _state.form.model = {}
    _state.form.formState = true
  },
  // 加载表单
  loadForm(context, par) {
    var _state = context.state
    console.log('加载表单参数', par)
    LoadFrom({ ID: par })
      .then(response => {
        const { Data } = response
        console.log(Data)
        _state.form.model = Data
        _state.form.formState = true
      })
      .catch(error => {
        console.log(error)
      })
  },
  //   save(context, par) {
  //     var _state = context.state
  //     par.sequenceNumber = parseInt(par.sequenceNumber)
  //     save(par)
  //       .then(response => {
  //         const { Data } = response
  //         console.log(Data)
  //         global.tools.msg('保存成功!', '成功')
  //         _state.form.formState = false

  //         context.dispatch('findList')
  //       })
  //       .catch(error => {
  //         console.log(error)
  //       })
  //   },
  findList(context, par) {
    console.log('feedback======findlist')
    var _state = context.state
    _state.dataList.listLoading = true
    pages(_state.dataList.searchForm)
      .then(res => {
        const { Data } = res
        console.log(Data)
        _state.dataList.list = Data.List
        _state.dataList.searchForm.pageIndex = Data.pageIndex
        _state.dataList.searchForm.pageSize = Data.pageSize
        _state.dataList.searchForm.dataCount = Data.count
        _state.dataList.searchForm.pageCount = Data.pages
        _state.dataList.listLoading = false
      })
      .catch(error => {
        console.log(error)
      })
  }
//   delete(context, par) {
//     console.log(par)
//     global.tools.confirm(
//       '确定要删除吗？',
//       function() {
//         Deletes({
//           id: par
//         })
//           .then(res => {
//             const { Data } = res
//             console.log(Data)
//             global.tools.msg('删除成功!', '成功')
//             context.dispatch('findList')
//           })
//           .catch(e => {
//             console.log(e)
//           })
//       },
//       null,
//       '提示'
//     )
//   }
  // loadTree(context) {
  //   var _state = context.state
  //   getShipAddressList()
  //     .then(res => {
  //       const { Data } = res
  //       console.log(Data)
  //       _state.dataList.getShipAddressList = Data
  //       // console.log(_state.dataList.productCategoryAllList)
  //     })
  //     .catch(error => {
  //       console.log(error)
  //     })
  // }
  // // handleSuccess(context, res) {
  //   if (res.Status === 1) {
  //     var _state = context.state
  //     if (res.Data.Parameter === 'Thumbnail') {
  //       //_state.form.model.coverImgState = true
  //       _state.form.model.CoverImg = res.Data.Url
  //     }
  //   } else {
  //     global.tools.msg('上传失败，请重新上传！', '错误')
  //   }
  // // }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
